import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;
import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.interfaces.DecodedJWT;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * TODO 添加类的描述
 *
 * @author zd
 * @version 1.0, 2023/8/25 17:53
 */
public class yongfanTest {
    private static final String Issuer = "雍繁数据";
    private static final String secret = "33e7d22cd39a4d0ca3ea8ab656243774"; // 目的是加盐，内容随意
    private static final String scrm_secret = "942294ad779a4b03a313fdc6095a57ef"; // 目的是加盐，内容随意

    @Test
    public void enterprise_token() {
        //先去数据库查询企业id
        String enterpriseId = "yfe491203";
        String audience = enterpriseId + "||" + enterpriseId;
        String token = JWT.create().withAudience(audience).withIssuer(Issuer).withIssuedAt(DateUtil.offsetMonth(new Date(), -1)).sign(Algorithm.HMAC256(scrm_secret));
        Map<String, Object> map = new HashMap<>();
        map.put("expire", DateUtil.tomorrow());
        map.put("value", token);
        System.out.println(JSON.toJSONString(map));
    }

    @Test
    public void user_token() {
        //查询该人的企业id和用户id
        String enterpriseId = "yfe492020";
        String userId = "yf491029";
        String audience = enterpriseId + "||" + userId;
        String token = JWT.create().withAudience(audience).withIssuer(Issuer).sign(Algorithm.HMAC256(secret));
        Map<String, Object> map = new HashMap<>();
        map.put("expire", DateUtil.tomorrow());
        map.put("value", token);
        System.out.println(token);
        System.out.println(JSON.toJSONString(map));
    }

    @Test
    public void test_enterprise_reset_pwd() {
        //默认重置为123456
        String initPwd = "123456";
        // ###从数据库读取user_enterprise表的create_time字段###
        String createTime = "2023-02-13 18:39:15.899";
        String hex = DigestUtils.md5Hex(initPwd);
        String password = DigestUtils.md5Hex(hex + createTime);
        //结果放到字段
        System.out.println(password);
    }
}
